package cn.itcast.search.web;

import cn.itcast.hmall.dto.common.PageDTO;
import cn.itcast.hmall.dto.common.ResultDTO;
import cn.itcast.hmall.dto.search.SearchReqDTO;
import cn.itcast.hmall.pojo.item.ItemDoc;
import cn.itcast.search.Service.SearchService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;


@RestController
@RequestMapping("/search")
public class searchController {
    @Autowired
    private SearchService searchService;

    /**
     * 全量数据导入接口
     *
     * @return
     */
    @GetMapping("/importItemData")
    public ResultDTO importItemData() {
        return searchService.importItemData();
    }

    /**
     * 搜索栏自动补全接口
     * @return
     */
    @GetMapping("/suggestion")
    public List<String> getSuggestions(@RequestParam("key") String key) {
        return searchService.getSuggestion(key);
    }

    //限定范围的聚合
    @PostMapping("/filters")
    public Map<String, List<String>> getFilters(@RequestBody SearchReqDTO searchReqDTO){
        return searchService.getFilters(searchReqDTO);
    }

    // 搜索酒店数据
    @PostMapping ("/list")
    public PageDTO<ItemDoc> search(@RequestBody SearchReqDTO searchReqDTO){
        return searchService.search(searchReqDTO);
    }








}